#!/usr/bin/env python3

import nbformat, os
from pathlib import Path

def read_nbs(path):
    "Check all notebooks in `path` (and subfolders) can be opened"
    path,nb_files = Path(path),[]
    for p,d,f in os.walk(path): nb_files += [Path(p)/f_ for f_ in f if f_.endswith('.ipynb')]
    for nb in nb_files:
        try: 
            with open(nb, 'r') as f: _ = nbformat.reads(f.read(), as_version=4)
        except Exception as e: 
            print(f"{nb} is corrupted and can't be opened.")
            raise e

read_nbs('nbs')